﻿using Orleans;
using System;
using System.Threading.Tasks;

namespace Service
{
    class Program
    {
        static void Main(string[] args)
        {


            // 定时器-
            // 提醒-
            // 订阅发布
            // 事务 尽可能
            // DotNetty

            if (args.Length > 0)
            {
                Console.WriteLine("args:"+args[0]);
            }


            var runTask = Run(args);

            Task.WaitAll(runTask);
        }

        static async Task<Task> Run(string[] args)
        {
            Console.WriteLine("Hello World!");

            var index = 99;

            if (args.Length == 0)
            {
                //Console.WriteLine("input service id:int");
                //await Task.Delay(TimeSpan.FromSeconds(3));
                //return Task.CompletedTask;
            }
            else
            {
                index = Convert.ToInt32(args[0]);
            }

            var context = new OrleansServiceBuilderContext
            {
                ClusterId = "dev",
                ServiceId = "sample",
                GatewayPort = 30000 + index,
                SiloPort = 11111 + index,
                IsUseDashboard = index == 1,
                DashboardContext = new Dashboard {
                    Username = "admin",
                    Password = "123456",
                    Port = 6666
                },
                ZookeeperConnectionString = "127.0.0.1:2181,127.0.0.1:2183,127.0.0.1:2183",
                MSSQLConnectionString = "Data Source=SLSQLDEV01;Initial Catalog=fbrsql;Integrated Security=True"
            };

            var hSilo = new OrleansServiceHelper(context);

            using (var host = await hSilo.StartAsync())
            {
                Console.WriteLine("\nService start success.\n");

                Console.ReadLine();

                await host.StopAsync();
            }

            return Task.CompletedTask;
        }

    }
}
